package com.wanglibao.woodtrade.woodtrade.ui.activity;

import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.WindowManager;
import android.widget.ListView;

import com.google.gson.Gson;
import com.wanglibao.woodtrade.woodtrade.R;
import com.wanglibao.woodtrade.woodtrade.config.NetConfig;
import com.wanglibao.woodtrade.woodtrade.entity.GoodsListEntity;
import com.wanglibao.woodtrade.woodtrade.jsonrpc.JsonRPCAsyncTask;
import com.wanglibao.woodtrade.woodtrade.model.impl.UserImpl;
import com.wanglibao.woodtrade.woodtrade.ui.activity.adapter.ItemLvMyCommodityActivityAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MyCommodityActivity extends BaseActivity {

    @Bind(R.id.lv_my_commodity_activity)
    ListView mLvMyCommodityActivity;
    //===============================
    ItemLvMyCommodityActivityAdapter mAdapter;
    List<String> mlist = new ArrayList<>();
    GoodsListEntity mGoodsListEntity;
    List<GoodsListEntity.ListBean> mListBeen;
    String store_id;
    Handler mHandler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            if (msg.arg2 != 2){
                mGoodsListEntity=new Gson().fromJson(msg.obj.toString(), GoodsListEntity.class);
                mListBeen=mGoodsListEntity.getList();
                mAdapter=new ItemLvMyCommodityActivityAdapter(MyCommodityActivity.this,mListBeen);
                mLvMyCommodityActivity.setAdapter(mAdapter);
            }

            return false;
        }
    });
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        setContentView(R.layout.activity_my_commodity);
        ButterKnife.bind(this);
        if (Build.VERSION.SDK_INT >= 19) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        } else {
            rl_common_title.setPadding(0, 0, 0, 0);
        }
        initData();
    }

    @Override
    protected void onResume() {
        super.onResume();
        NetWorking();
    }

    private void initData() {
        tvTitle.setText("我的商品");
        tvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        store_id=new UserImpl(this).getUser().id;
    }
    public void NetWorking() {
        JsonRPCAsyncTask jsonRPCAsyncTask = new JsonRPCAsyncTask(this, NetConfig.SERVER + NetConfig.TYPE_USER,
                NetConfig.userGoodsLists, mHandler,
                "jsonObject", NetConfig.TaskId.userGoodsLists, new Object[]{new UserImpl(this).getUser().token});
        jsonRPCAsyncTask.execute(new Void[]{});
    }

}
